package org.genntii.warehousesystem.controller;


import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.genntii.warehousesystem.common.Result;
import org.genntii.warehousesystem.domain.entity.Type;
import org.genntii.warehousesystem.service.TypeService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "货品类别接口")
@RestController
@RequestMapping("/type")
public class TypeController {

    @Resource
    private TypeService typeService;

    @Operation(summary = "添加类别")
    @Parameter(name = "type",description = "类别名",required = true,in = ParameterIn.QUERY)
    @PostMapping("/v1/add")
    public Result add(@RequestParam("type") String type){
        typeService.add(type);
        return Result.success();
    }

    @Operation(summary = "删除类别")
    @Parameter(name = "id",description = "类别id",required = true,in = ParameterIn.QUERY)
    @DeleteMapping("/v1/del")
    public Result del(@RequestParam("id") int id){
        typeService.del(id);
        return Result.success();
    }

    @Operation(summary = "分页获取类别信息")
    @Parameter(name = "type",description = "类别id",required = true,in = ParameterIn.QUERY)
    @GetMapping("/v1/getType")
    public Result<List<Type>> getTypeByPage(@RequestParam("page")int page){
        return Result.success(typeService.showAllByPage(page));
    }

    @Operation(summary = "获取全部类别")
    @GetMapping("getType")
    public Result<List<Type>> getType(){
        return Result.success(typeService.showAllType());
    }

}
